package com.chixing.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirecterRabbitConfig implements BeanPostProcessor {
    // 添加通知交换机和队列配置
    @Bean("wsExchange")
    public DirectExchange notificationExchange() {
        return new DirectExchange("wsExchange",true,false);
    }
    //2. 创建队列
    @Bean("wsQueue")
    public Queue ticketPurchasedQueue() {
        return new Queue("wsQueue");
    }


    @Bean("wsbind")
    public Binding wsBinding(@Qualifier("wsQueue") Queue queue,
                             @Qualifier("wsExchange") DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("key1"); // 绑定routingKey
    }
    /**
     * Json转换器
     */
    @Bean
    public Jackson2JsonMessageConverter jsonMessageConverter(){
        return new Jackson2JsonMessageConverter();
    }
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }
}
